package com.sz.common.core.system.service.impl;

import com.sz.common.base.dao.ParamData;
import com.sz.common.base.service.AbstractService;
import com.sz.common.core.service.PrincipalUtils;
import com.sz.common.core.system.entity.SysDict;
import com.sz.common.core.system.service.SysDictService;
import com.sz.common.core.system.service.SysFileService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Function: SysDict实现类 <br>
 * Author: hpeng.wang <br>
 * Date: 2017-01-20 11:08:00
 */
@Service("sysDictService")
public class SysDictServiceImpl extends AbstractService implements SysDictService {
    @Autowired
    SysFileService fileService;

    @Override
    protected String getMapperNamespace() {
        return "SysDictMapper";
    }

    @Override
    public List<SysDict> findByCatalog(String catalog) {
        ParamData pd = new ParamData();
        pd.put("catalog", catalog);
        pd.put("language", PrincipalUtils.getLocalLanguage());//获取当前的语言
        List<SysDict> list = dao.findForList(getSqlName("findByCatalog"), pd, SysDict.class);
        return list;
    }

    @Override
    public Map<String, String> findMapByCatalog(String catalog) {
        List<SysDict> sysDictList = this.findByCatalog(catalog);
        Map<String, String> sysDictMap = new HashMap<>();
        for (SysDict sysDict : sysDictList) {
            sysDictMap.put(sysDict.getCode(), sysDict.getName());
        }
        return sysDictMap;
    }

    @Override
    public String getNameByCode(String catalog, String code) {
        ParamData pd = new ParamData();
        pd.put("catalog", catalog);
        pd.put("code", code);
        pd.put("language", PrincipalUtils.getLocalLanguage());//获取当前的语言
        SysDict sysDict = (SysDict) dao.findForObject(getSqlName("findByParams"), pd);
        return sysDict == null ? "" : sysDict.getName();
    }

    @Override
    public List<SysDict> queryOrderFileTypes(String catalog, String codePrefix) {
        ParamData pd = new ParamData();
        pd.put("catalog", catalog);
        pd.put("codePrefix", codePrefix);
        pd.put("language", PrincipalUtils.getLocalLanguage());//获取当前的语言
        List<SysDict> dictList = dao.findForList(getSqlName("findOrderFileType"),pd,SysDict.class);
        return dictList;
    }
}
